<!DOCTYPE html>
<!--
 * Copyright (c) 2009 The Chromium Authors. All rights reserved.  Use of this
 * source code is governed by a BSD-style license that can be found in the
 * LICENSE file.
-->
<html>
  <head>
    <script type="text/javascript" src="chrome_ex_oauthsimple.js"></script>
    <script type="text/javascript" src="chrome_ex_oauth.js"></script>
    <script type="text/javascript">
      var oauth = ChromeExOAuth.initBackgroundPage({
        'request_url' : 'http://www.flickr.com/services/oauth/request_token',
        'authorize_url' : 'http://www.flickr.com/services/oauth/authorize',
        'access_url' : 'http://www.flickr.com/services/oauth/access_token',
        'consumer_key' : '473dff16c3afe491ead821b977241034',
        'consumer_secret' : '0b77cfa0cd0ae052',
        'scope' : 'http://api.flickr.com/services/',
        'app_name' : 'flickr - OAuth Contacts'
      });

      var contacts = null;

      function setIcon() {
        if (oauth.hasToken()) {
          chrome.browserAction.setIcon({ 'path' : 'img/icon-19-on.png'});
        } else {
          chrome.browserAction.setIcon({ 'path' : 'img/icon-19-off.png'});
        }
      };

      function onContacts(text, xhr) {
        contacts = [];
        var data = JSON.parse(text);
		console.log(data);
		var contact = {
            'name' : data['group']['name']['_content'],
            'description' : data['group']['description']['_content'],
            'members' : data['group']['members']['_content']
        };
        
        contacts.push(contact);

        chrome.tabs.create({ 'url' : 'contacts.html'});
      };

      function getContacts() {
        oauth.authorize(function() {
          console.log("on authorize");
          setIcon();
          var url = "http://api.flickr.com/services/rest/";
          oauth.sendSignedRequest(url, onContacts, {
            'parameters' : {
              'format' : 'json',
			  'nojsoncallback':1,
              'method' : 'flickr.groups.getInfo',
			  'group_id' : '52239802417@N01'
            }
          });
        });
      };

      function logout() {
        oauth.clearTokens();
        setIcon();
      };

      setIcon();
      chrome.browserAction.onClicked.addListener(getContacts);

    </script>
  </head>
  <body>
  </body>
</html>
